package com.changhai.diabetes.action;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.changhai.diabetes.model.OpertResultMsg;
import com.changhai.diabetes.model.SportsSurvey;
import com.changhai.diabetes.model.SportsSuifang;
import com.changhai.diabetes.model.SportsTreatment;
import com.changhai.diabetes.service.SportService;

/**
 * 运动
 * 
 * @author Andy
 * 
 */
public class SportsAction extends BaseAction {

	private static final long serialVersionUID = 4392936553263004630L;
	private OpertResultMsg opertMsg;
	private Long patientid;
	private SportsSurvey sportsSurvey;
	private SportsSuifang sportsSuifang;
	private SportsTreatment sportsTreat;
	private SportService sportService;
	private Integer flag = 0;

	public String execute() throws Exception {
		return super.execute();
	}

	public String query() {
		return "input";
	}

	public String editSportsSurvey() {
		if (patientid != null && patientid > 0) {
			try {
				sportsSurvey = sportService.searchSurveyByPatientId(patientid);
				tbList = this.getTableForEnter(patientid, flag);
			} catch (Exception e) {
				e.printStackTrace();
				opertMsg = new OpertResultMsg(Long.valueOf(1), "暂无运动信息!");
			}
			return "input";
		} else {
			return "query";
		}
	}

	public String saveEditSportsSurvey() {
		if (patientid == null || patientid <= 0 || sportsSurvey == null) {
			opertMsg = new OpertResultMsg(Long.valueOf(1), "参数错误!");
		} else {
			try {
				sportService.saveEditSportsSurvey(sportsSurvey);
				opertMsg = new OpertResultMsg(Long.valueOf(0), "保存成功!");
				commonService.writeLogToFile("update", "运动调查", patientid);
			} catch (Exception e) {
				opertMsg = new OpertResultMsg(Long.valueOf(1), "保存失败!");
			}
		}
		return this.editSportsSurvey();
	}

	public String saveNewSportsSurvey() {
		if (patientid == null || patientid <= 0 || sportsSurvey == null) {
			opertMsg = new OpertResultMsg(Long.valueOf(1), "参数错误!");
		} else {
			try {
				sportService.saveNewSportsSurvey(sportsSurvey);
				opertMsg = new OpertResultMsg(Long.valueOf(0), "保存成功!");
				commonService.writeLogToFile("insert", "运动调查", patientid);
			} catch (Exception e) {
				opertMsg = new OpertResultMsg(Long.valueOf(1), "保存失败!");
			}
		}
		return this.editSportsSurvey();
	}

	public String insertNewSportsSuifang() {
		sportsSuifang.setPatientid(patientid);
		tbList = this.getTableForEnter(patientid, flag);
		return "input";
	}

	public String editSportsTreat() {
		if (patientid != null && patientid > 0) {
			try {
				sportsTreat = sportService.searchTreatByPatientId(patientid);
				tbList = this.getTableForEnter(patientid, flag);
			} catch (Exception e) {
				e.printStackTrace();
				opertMsg = new OpertResultMsg(Long.valueOf(1), "暂无运动信息!");
			}
			return "input";
		} else {
			return "query";
		}
	}

	public String editSportsSuifang() {
		if (patientid != null && patientid > 0) {
			try {
				sportsSuifang = sportService.searchSuifangByPatientId(patientid);
				tbList = this.getTableForEnter(patientid, flag);
			} catch (Exception e) {
				e.printStackTrace();
				opertMsg = new OpertResultMsg(Long.valueOf(1), "暂无运动随访信息!");
			}
			return "input";
		} else {
			return "query";
		}
	}

	public String saveEditSportsTreat() {
		if (patientid == null || patientid <= 0 || sportsTreat == null) {
			opertMsg = new OpertResultMsg(Long.valueOf(1), "参数错误!");
		} else {
			try {
				sportService.saveEditSportsTreat(sportsTreat);
				opertMsg = new OpertResultMsg(Long.valueOf(0), "保存成功!");
				commonService.writeLogToFile("update", "运动治疗", patientid);
			} catch (Exception e) {
				opertMsg = new OpertResultMsg(Long.valueOf(1), "保存失败!");
			}
		}
		return this.editSportsTreat();
	}

	public String saveEditSportsSuifang() {
		if (patientid == null || patientid <= 0 || sportsSuifang == null) {
			opertMsg = new OpertResultMsg(Long.valueOf(1), "参数错误!");
		} else {
			try {
				sportService.saveEditSportsSuifang(sportsSuifang);
				opertMsg = new OpertResultMsg(Long.valueOf(0), "保存成功!");
				commonService.writeLogToFile("update", "运动随访", patientid);
			} catch (Exception e) {
				opertMsg = new OpertResultMsg(Long.valueOf(1), "保存失败!");
			}
		}
		return this.editSportsSuifang();
	}

	public String saveNewSportsTreat() {
		if (patientid == null || patientid <= 0 || sportsTreat == null) {
			opertMsg = new OpertResultMsg(Long.valueOf(1), "参数错误!");
		} else {
			try {
				sportService.saveNewSportsTreat(sportsTreat);
				opertMsg = new OpertResultMsg(Long.valueOf(0), "保存成功!");
				commonService.writeLogToFile("insert", "运动治疗", patientid);
			} catch (Exception e) {
				opertMsg = new OpertResultMsg(Long.valueOf(1), "保存失败!");
			}
		}
		return this.editSportsTreat();
	}

	public String saveNewSportsSuifang() {
		if (patientid == null || patientid <= 0 || sportsSuifang == null) {
			opertMsg = new OpertResultMsg(Long.valueOf(1), "参数错误!");
		} else {
			try {
				sportService.saveNewSportsSuifang(sportsSuifang);
				opertMsg = new OpertResultMsg(Long.valueOf(0), "保存成功!");
				commonService.writeLogToFile("insert", "运动随访", patientid);
			} catch (Exception e) {
				opertMsg = new OpertResultMsg(Long.valueOf(1), "保存失败!");
			}
		}
		return this.editSportsSuifang();
	}

	public OpertResultMsg getOpertMsg() {
		return opertMsg;
	}

	public void setOpertMsg(OpertResultMsg opertMsg) {
		this.opertMsg = opertMsg;
	}

	public Long getPatientid() {
		return patientid;
	}

	public void setPatientid(Long patientid) {
		this.patientid = patientid;
	}

	public SportsSurvey getSportsSurvey() {
		return sportsSurvey;
	}

	public void setSportsSurvey(SportsSurvey sportsSurvey) {
		this.sportsSurvey = sportsSurvey;
	}

	public SportService getSportService() {
		return sportService;
	}

	public void setSportService(SportService sportService) {
		this.sportService = sportService;
	}

	public SportsSuifang getSportsSuifang() {
		return sportsSuifang;
	}

	public void setSportsSuifang(SportsSuifang sportsSuifang) {
		this.sportsSuifang = sportsSuifang;
	}

	public SportsTreatment getSportsTreat() {
		return sportsTreat;
	}

	public void setSportsTreat(SportsTreatment sportsTreat) {
		this.sportsTreat = sportsTreat;
	}

	public Integer getFlag() {
		return flag;
	}

	public void setFlag(Integer flag) {
		this.flag = flag;
	}
}
